// pages/feedback/feedback.js
Page({
  data: {
    tabs: [
      {
        id: 0,
        value: "体验问题",
        isActive: true
      },
      {
        id: 1,
        value: "商品、商家投诉",
        isActive: false
      }
    ],
    chooseImages: [],
    textVal: ""
  },
  upLoadImgs: []
  ,
  tabsItemChange(e) {
    const {index} = e.detail;
    //修改源数据
    let {tabs} = this.data;
    tabs.forEach((v, i) => {
      i === index ? v.isActive = true : v.isActive = false;
    });
    this.setData({
      tabs
    });
  },
  //点击添加图片
  onAddImgs(){
    //调用小程序内置选择图片的api
    wx.chooseImage({
      //同时选中图片数量
      count: 0,
      // 图片格式 原图 压缩
      sizeType: ['original','compressed'],
      //图片  照相机
      sourceType: ['album','camera'],
      success: (result) => {
        this.setData({
          chooseImages: [...this.data.chooseImages, ...result.tempFilePaths] 
        });
      }
    })
  },
  // 删除图片
  onDelImg(e) {
    const {index} = e.currentTarget.dataset;
    let {chooseImages} = this.data;
    chooseImages.splice(index, 1);
    this.setData({
      chooseImages
    });
  },
  //获取文本
  EInput(e) {
    this.setData({
      textVal: e.detail.value
    });
  },
  // 表单提交
  onSubmit() {
    const {textVal} = this.data;
    //合法性验证
    if (!textVal.trim()) {
      wx.showToast({
        title: '输入不合法！',
        icon: 'none',
        mask: true
      });
      return ;
    } 
    //准备上传数据
    this.setData({
      textVal: "",
      chooseImages: []
    });
    wx.showToast({
      title: '提交成功',
      mask:true
    });
    let times =setTimeout(() => {
      wx.navigateBack();
      clearTimeout(times);
    }, 2000);
  }
})